﻿<!DOCTYPE html>
<html>
<head>
    <title>更新栏目</title>
</head>
<body>

    <div class="tabarea1">
        <div id="area" class="area" style="overflow-y:auto;">
            <form action="" method="post">
                <div class="form" id="form1">
                    <input type="hidden" field="Lft" />
                    <div class="title" style="margin-top:0"><span class="icon icon1"></span>基本</div>
                    <dl class="hidden">
                        <dt>上级栏目：</dt>
                        <dd>
                            <span class="input">
                                <select field="ParentLft" class="tb_normal">
                                    <option value="1" style="color:Red">一根目录一</option>
                                    ${categories}
                                </select>
                            </span>
                            <span class="desc" style="color:Red">注:上级栏目指定后,不可修改!</span>
                        </dd>
                    </dl>

                    <dl>
                        <dt>名称：</dt>
                        <dd>
                            <input type="text" class="tb_normal ui-validate" required="true" length="[0,50]" summary="{required:'不能为空!',length:'长度不能超过50位!'}" field="Name" id="name" />
                        </dd>
                    </dl>
                    <dl>
                        <dt>栏目标识：</dt>
                        <dd>
                            <input type="text" class="tb_normal ui-validate" field="Tag" id="tag" size="20" /><a style="margin-left:5px" href="javascript:;" summary="{required:'不能为空',strerr:'长度为50位以下的字母，数字，下划线和连接线的组合'}">自动标识</a> <br /><span class="desc" style="padding-left:60px">建议手动填写,用于调用数据的唯一标识,且显示在地址栏中,如http://www.ops.cc/news/,news就是一个标识</span>
                        </dd>
                    </dl>
                    <dl>
                        <dt>重定向：</dt>
                        <dd>
                            <input type="radio" class="radio" field="IsRedirect" name="IsRedirect" id="IsRedirect1" value="0" checked="checked" /><label for="IsRedirect1">否</label>
                            <input type="radio" class="radio" field="IsRedirect" name="IsRedirect" id="IsRedirect2" value="1" /><label for="IsRedirect1">是</label>

                            <span id="redirectPanel" class="hidden" style="padding-left:20px">
                                网址(URL)：<input class="tb_normal ui-validate" length="[0,150]" name="location" field="Location" />
                            </span>
                            <br /> <span class="desc" style="padding-left:60px">提示：重定向可以将栏目页面跳转到指定的网址。</span>
                        </dd>
                    </dl>

                    <dl>
                        <dt>图标：</dt>
                        <dd>
                            <img id="icon_img" style="display:none;width: 80px; height: 80px; position: absolute; left: 5px; top: 0px" />
                            <input class="tb_normal ui-validate" length="[0,100]" type="text" readonly="readonly" field="Icon" id="icon" />
                            <span id="upload_icon">上传缩略图</span>
                        </dd>
                    </dl>
                    <dl style="display:none">
                        <dt>模块：</dt>
                        <dd>
                            <select class="tb_normal" field="ModuleId">${categoryTypes}</select>
                        </dd>
                    </dl>
                    <dl>
                        <dt>排序：</dt>
                        <dd>
                            <input class="tb_normal ui-validate" isnumber="true" field="OrderIndex" style="width:50px;" value="0" />
                        </dd>
                    </dl>


                    <div class="title"><span class="icon icon1"></span>模板设置</div>
                    <dl>
                        <dt>视图：</dt>
                        <dd>
                            <select field="CategoryTemplate" id="CategoryTemplate" class="tb_normal"><option value="">一默认一</option>${category_tpls} </select><span class="desc">注：默认则使用模块的视图设置</span>
                        </dd>
                    </dl>


                    <dl>
                        <dt>文档视图：</dt>
                        <dd>
                            <select field="CategoryArchiveTemplate" id="CategoryArchiveTemplate" class="tb_normal"> <option value="">一默认一</option>${archive_tpls}</select><span class="desc">注：默认则使用模块（或文档）的视图设置</span>
                        </dd>
                    </dl>

                    <div class="title"><span class="icon icon1"></span>SEO设置</div>
                    <dl>
                        <dt>标题：</dt>
                        <dd>
                            <textarea class="tb_normal ui-validate" length="[0,100]" field="PageTitle" name="PageTitle" style="width:500px;height:25px;"></textarea>
                        </dd>
                    </dl>
                    <dl>
                        <dt>关键字：</dt>
                        <dd>
                            <textarea class="tb_normal ui-validate" length="[0,100]" field="Keywords" style="width:500px;height:25px;"></textarea>
                        </dd>
                    </dl>
                    <dl>
                        <dt>描述：</dt>
                        <dd>
                            <textarea class="tb_normal ui-validate" length="[,200]" field="Description" style="width:500px;height:75px;"></textarea>
                        </dd>
                    </dl>

                    <dl>
                        <dt>&nbsp;</dt>
                        <dd>
                            <a id="btn" class="btn" href="javascript:;">保存</a>
                        </dd>
                    </dl>

                </div>
            </form>
        </div>

    </div>

    <script type="text/javascript">
        var entity = ${entity} ||{};
        entity.ParentLft = ${parentLft};
        entity.IsRedirect = (entity.Location||'').length!=0;
        cms.json.bind('form1',entity);

        var tag = cms.$("tag"),
        nameEle = cms.$("name");

        //上传图标
        var icon_upload = cms.upload({
            id: 'upload_icon',
            debug: !true,
            url: '?module=upload&action=uploadimage&for=&upload.id=icon_upload',
            exts: '*.gif;*.jpg;*.png;*.bmp'
        },function (result, data) {
            if (result) {
                cms.$('icon').value = data.url;
                cms.$('icon_img').src = data.url;
            } else {
                alert('上传失败：' + data);
            }
        });


        tag.onblur = function () {
            if (this.value == '') {
                cms.validator.setTip(this.nextSibling, false, 'required');
            } else {
                this.value = this.value.toLowerCase();
                if (!/^[a-z0-9_-]{1,50}$/.test(this.value)) {
                    cms.validator.setTip(this.nextSibling, false, 'strerr');
                } else {
                    cms.validator.removeTip(this.nextSibling);
                }
            }
        };

        //设置是否跳转显示
        var redirectPanel = cms.$('redirectPanel');
        cms.$('IsRedirect1').onchange = cms.$('IsRedirect2').onchange = function(){
            if(this.checked){
                if(this.value == '1'){
                    redirectPanel.className = '';
                }else{
                    redirectPanel.className = 'hidden'
                }
            }
        };
        if(entity.IsRedirect)redirectPanel.className='';


        tag.nextSibling.onclick = function () {
            var e = this;
            var txt = this.innerHTML;
            var _title = nameEle.value;
            if (_title == '') {
                cms.validator.setTip(e, false, null, '请先栏目名称!');
            } else {
                this.innerHTML = '获取中...';
                cms.xhr.post('?', 'module=ajax&action=getspellword&word=' + encodeURIComponent(_title), function (result) {
                    e.previousSibling.value = result.toLowerCase();
                    e.previousSibling.onblur();
                    e.innerHTML = txt;
                }, function () {
                    cms.validator.setTip(e, false, null, '获取失败,请重试!');
                });
            }
        };


        window.saveData = function () {
            if (cms.validator.validate()) {
                var data=cms.json.toObject('form1');
                if(data.IsRedirect=='0')data.Location='';
                cms.xhr.jsonPost(
                    '${url}',
                     data,
                     function (json) {
                         if (json.result) {
                             if (window._reloadTree) window._reloadTree();
                             parent.M.alert(json.message);
                         } else {
                             parent.M.alert(json.message);
                         }
                     });
            }
        };

        cms.$('btn').onclick = window.saveData;
        cms.validator.init('form1');
    </script>
</body>
</html>
